home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.19981211-19990422 / 000447_news@watsun.cc.columbia.edu _Mon Apr 19 14:22:13 1999.msg < prev    next >
Internet Message Format  |  2020-01-01  |  6KB

  1. Return-Path: <news@watsun.cc.columbia.edu>
  2. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
  3.     by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id OAA03902
  4.     for <kermit.misc@watsun.cc.columbia.edu>; Mon, 19 Apr 1999 14:22:12 -0400 (EDT)
  5. Received: (from news@localhost)
  6.     by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id OAA13809
  7.     for kermit.misc@watsun.cc.columbia.edu; Mon, 19 Apr 1999 14:04:24 -0400 (EDT)
  8. X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
  9. From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
  10. Subject: Re: Help on shell script doing ftp
  11. Date: 19 Apr 1999 18:04:19 GMT
  12. Organization: Columbia University
  13. Message-ID: <7ffr73$dfe$1@newsmaster.cc.columbia.edu>
  14. To: kermit.misc@watsun.cc.columbia.edu
  15.  
  16. In article <7ff65g$f9d$1@news1.global-one.dk>,
  17. Jan Fjeldmark <jfj.it@dsg.dk> wrote:
  18. : Stefan A. Deutscher wrote:
  19. : >On Fri, 9 Apr 1999 19:05:20 -0500, steve VanArsdale
  20. : ><first.consultant@picksys.com> wrote:
  21. : >>i am looking for a workaround for ftp in an batch AIX shell script.
  22. : >>
  23. : >>Specifically, we need the script to open an ftp session to a remote AIX
  24. : >>system with both the login and the password, check for the existence of
  25. : >>a file, and if not present, put the file on the remote directory. If
  26. : >>the file is present on the remote directory the script must record an
  27. : >>error and exit without putting the file.
  28. : >>
  29. : >>ftp always prompts for the password, and we can't figure out how to
  30. : >>make the script conditional on the presence of the file in the remote
  31. : >>directory.
  32. : >
  33. : >Unless it _has_ to be ftp/ftpd you could try a small kermit script.
  34. : >That's at least what I'd do. Cheer,  Stefan
  35. : Like telnet, ftp uses .netrc to login to foreign hosts. Put this line in
  36. : .netrc:
  37. : machine myhost login myname password mypw
  38. : Now ftp won't prompt for userid or password.
  39. : To test for presence of a specific file on the remote host and act
  40. : correspondingly, you wil have to run ftp several times and analyse the out
  41. : using grep or similar.
  42. Or as Stephan suggests, you can use Kermit instead of FTP.
  43.  
  44. : >>Specifically, we need the script to open an ftp session to a remote AIX
  45. : >>system with both the login and the password, check for the existence of
  46. : >>a file, and if not present, put the file on the remote directory. If
  47. : >>the file is present on the remote directory the script must record an
  48. : >>error and exit without putting the file.
  49. :
  50. Here's an illustration using C-Kermit 7.0 Beta.06:
  51.  
  52.   http://www.columbia.edu/kermit/ck70.html
  53.  
  54. --(cut here)--
  55. #/usr/local/bin/kermit +
  56.  
  57. define fatal { hangup, exit 1 \%1 }
  58.  
  59. set network type tcp/ip
  60. if fail exit 1 { Sorry, this version of C-Kermit does not support TCP/IP.}
  61.  
  62. while not def \%1 {            ; If hostname/address not supplied
  63.     ask \%1 { Host: }          ; prompt for one until we get it.
  64.     if > \fsplit(\%1) 1 {      ; Allow only one "word" here.
  65.         echo Just the address please.  ; E.g. no TCP port number.
  66.         undef \%1
  67.     }
  68. }
  69. if not def \%2 {                       ; If username not supplied
  70.     ask \%2 { User [\v(user)]: }       ; Prompt for one, but default
  71.     if not def \%2 assign \%2 \v(user) ; to local user ID.
  72. }
  73. echo Connecting to \%1 as user \%2...
  74.  
  75. set host \%1 23
  76. if fail exit 1 Can't open Telnet connection to \%1.
  77.  
  78. ; Prompt for password if necessary only after connection is made
  79. ; (because there's no point in asking for it if the connection failed).
  80.  
  81. while not defined \%3 {
  82.     askq \%3 { Password for \%2 at \%1: }
  83. }
  84. set input echo off             ; Don't echo scripted interactions.
  85.  
  86. ; Get any of several possible login prompts:
  87.  
  88. minput 20 login: Username: Password: {Password for \%2:}
  89. if fail exit 1 Timed out waiting for initial prompt: \v(inwait) sec.
  90. if ( = \v(minput) 1 || = \v(minput) 2 ) {
  91.     lineout \%2                ; User ID required - send it.
  92.     minput 10 Password: {Password for \%2:}
  93.     if fail exit 1 Timed out waiting for Password prompt: \v(inwait) sec.
  94. }
  95. lineout \%3                    ; Send password
  96. undef \%3                      ; Erase password from memory
  97. set exit on-disconnect on      ; Exit automatically if connection broken.
  98.  
  99. ; Start Kermit server on the remote end
  100. ;
  101. lineout kermit -x
  102.  
  103. ; From this point all commands are issued from the client.
  104. ;
  105. ; Let's say the directory in question is /tmp/test
  106. ; and the filename is foo.  Of course you could use variables here.
  107. ;
  108. log transactions               ; Keep a record of file transfers
  109.  
  110. remote cd /tmp/test
  111. if fail fatal {Can't CD to /tmp/test}
  112.  
  113. remote query files(foo)
  114. if = \v(query) 0 {
  115.     writeln transactions File "foo" already exists on server.
  116.     echo File "foo" already exists on server - quitting...
  117.     exit 0
  118. }
  119. send foo
  120. if fail fatal {Upload failed}
  121. bye
  122. exit 0 Upload succeeded
  123. ---(cut here)---
  124.  
  125. Save this file under whatever name you want, give it execute permission,
  126. and then run it as if it were a shell script.  The host, username, and
  127. password can be given as arguments on the command line; if they are not
  128. given, the script prompts you for them.
  129.  
  130. You can simplify the upload part considerably by telling the server to
  131. "set file collision discard" -- meaning if the client tries to send it a
  132. file whose name is the same as a file already present at the server, the
  133. server rejects it.  Other options include "set file collision update",
  134. meaning to accept the incoming file only if it is newer than the existing one.
  135.  
  136. - Frank